package cache_service

import (
	"go-gin-example/pkg/e"
	"strconv"
	"strings"
)

type Author struct {
	ID         int
	Name       string
	Department string

	PageNum  int
	PageSize int
}

// 获取author 缓存key
func (a *Author) GetAuthorKey() string {
	return e.CACHE_AUTHOR + "_" + strconv.Itoa(a.ID)
}

func (a *Author) GetAuthorsKey() string {
	keys := []string{
		e.CACHE_AUTHOR,
		"LIST",
	}

	if a.ID > 0 {
		keys = append(keys, strconv.Itoa(a.ID))
	}

	if a.Name != "" {
		keys = append(keys, a.Name)
	}

	if a.PageNum > 0 {
		keys = append(keys, strconv.Itoa(a.PageNum))
	}

	if a.PageSize > 0 {
		keys = append(keys, strconv.Itoa(a.PageSize))
	}

	return strings.Join(keys, "_")

}
